package com.bll.imple.insuranceCustomAction;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bean.InsuranceCustomBean;
import com.bll.Action;
import com.dao.InsuranceCustomDao;

public class AddInsuranceCustomAction implements Action {

	public String execute(HttpServletRequest request,
			HttpServletResponse response) {
		String Sex=request.getParameter("sex");
		String Birthdate= request.getParameter("birthdate");
		String Marital= request.getParameter("marital");
		String children= request.getParameter("children");
		String oldman= request.getParameter("oldman");
		String Loan= request.getParameter("loan");
		String Security= request.getParameter("security");
		String Name= request.getParameter("name");
		String Tel= request.getParameter("tel");
		String Info= request.getParameter("info");
		Date date=new Date();
		String Time=date.toLocaleString();
		
		int userid= Integer.parseInt(request.getSession().getAttribute("userId").toString());
		
		InsuranceCustomBean icb=new InsuranceCustomBean(); 
		
		icb.setSex(Sex);
		icb.setBirthdate(Birthdate);
		icb.setMarital(Marital);	
		icb.setChildren(children);
		icb.setOldman(oldman);
		icb.setLoan(Loan);
		icb.setSecurity(Security);
		icb.setName(Name);
		icb.setTel(Tel);
		icb.setInfo(Info);
		icb.setTime(Time);
		icb.setUserId(userid);
		
		String path=request.getServletPath();
		String lujing=path.substring(path.indexOf("/")+1, path.length());
		if(lujing.equals("AddInsuranceCustom1.ins")){
		    request.setAttribute("ICbean", icb);
		    return "sirendingzhijieguo.jsp";
		}else{
			InsuranceCustomDao dao=new InsuranceCustomDao();
			int n=dao.addInsuranceCustom(icb);
			if(n>0){
				
	        	return "dzcg.jsp";
			}else{
				return "sirendingzhijieguo.jsp";
			}
		}
		
		
		
	}

}
